<%-- 
  -- Body New para Student.
  --
  -- @author pablo.tortorella
--%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<%@ taglib uri="/WEB-INF/struts-html-el-1.2.8.tld" prefix="html-el"%>
<%@ taglib uri="/WEB-INF/struts-logic-el-1.2.8.tld" prefix="logic-el"%>
<%@ taglib uri="/WEB-INF/security.tld" prefix="security" %>

<%@ taglib uri="http://struts.apache.org/tags-bean-el" prefix="bean2"%>

<script src="<html:rewrite page='/protected/script/util.js'/>" type="text/javascript"></script>

<%-- Para EXT --%>
<link rel="stylesheet" type="text/css" href="<html:rewrite page='/protected/script/ext-1.1.1/resources/css/ext-all.css'/>" />

<script src="<html:rewrite page='/protected/script/ext-1.1.1/adapter/ext/ext-base.js'/>" type="text/javascript"></script>
<script src="<html:rewrite page='/protected/script/ext-1.1.1/ext-all.js'/>" type="text/javascript"></script>

<%-- prototype esta en el main layout --%>
<script src="<html:rewrite page='/protected/script/scriptaculous/scriptaculous.js'/>" type="text/javascript"></script>

<script type="text/javascript">
    /** Crea un participante */
    function createStudent() {
		if (!validate()) {
			return;
		}
        var nameObj = $("createNameId");
        var surnameObj = $("createSurnameId");
        var selectedIdTypeObj = $("createIdTypeId");
        var personalIdObj = $("createPersonalIdId");
        var nationalityObj = $("createNationalityId");
        var emailObj = $("createEmailId");
        var email2Obj = $("createEmail2Id");
        var phoneObj = $("createPhoneId");
        var workPhoneObj = $("createWorkPhoneId");
        var mobileObj = $("createMobileId");
        var streetObj = $("createStreetId");
        var numberObj = $("createNumberId");
        var floorObj = $("createFloorId");
        var roomObj = $("createRoomId");
        var zipCodeObj = $("createZipCodeId");
        var cityObj = $("createCityId");
        var townObj = $("createTownId");
        var companyObj = $("createCompanyId");
        var positionObj = $("createPositionId");
        var degreeNameObj = $("createDegreeNameId");
        var universityObj = $("createUniversityId");
        var degreeYearObj = $("createDegreeYearId");
        var createCustomerObj = $("createCreateCustomerId");
        var completeObj = $("createCompleteId");
        
        nameObj.value = $("nameId").value;
        surnameObj.value = $("surnameId").value;
        selectedIdTypeObj.value = $("selectedIdTypeId").value;
        personalIdObj.value = $("personalIdId").value;
        nationalityObj.value = $("nationalityId").value;
        emailObj.value = $("emailId").value;
        email2Obj.value = $("email2Id").value;
        phoneObj.value = $("phoneId").value;
        workPhoneObj.value = $("workPhoneId").value;
        mobileObj.value = $("mobileId").value;
        streetObj.value = $("addressStreetId").value;
        numberObj.value = $("addressNumberId").value;
        floorObj.value = $("addressFloorId").value;
        roomObj.value = $("addressRoomId").value;
        zipCodeObj.value = $("addressZipCodeId").value;
        cityObj.value = $("addressCityId").value;
        townObj.value = $("addressTownId").value;
        companyObj.value = $("companyId").value;
        positionObj.value = $("positionId").value;
        degreeNameObj.value = $("degreeNameId").value;
        universityObj.value = $("universityId").value;
        degreeYearObj.value = $("degreeYearId").value;
        createCustomerObj.value = $("createCustomerId").checked;
        completeObj.value = $("completeId").checked;
        var form = $("createStudentFormId");
        form.submit();
    }
    
    function validate() {
    	if (Util.valid.isBlank($("nameId").value)) {
            Ext.MessageBox.alert('Error', 'Debe ingresar el nombre. ');
            $("nameId").focus();
            return false;
        }
		if (Util.valid.isBlank($("surnameId").value)) {
            Ext.MessageBox.alert('Error', 'Debe ingresar el apellido. ');
            $("surnameId").focus();
            return false;
        }
        if (Util.valid.isBlank($("personalIdId").value)) {
            Ext.MessageBox.alert('Error', 'Debe ingresar el documento. ');
            $("personalIdId").focus();
            return false;
        }
        if (Util.valid.isBlank($("nationalityId").value)) {
            Ext.MessageBox.alert('Error', 'Debe ingresar la nacionalidad. ');
            $("nationalityId").focus();
            return false;
        }
        if (Util.valid.isBlank($("addressStreetId").value)) {
            Ext.MessageBox.alert('Error', 'Debe ingresar la calle. ');
            $("addressStreetId").focus();
            return false;
        }
        if (Util.valid.isBlank($("addressNumberId").value)) {
            Ext.MessageBox.alert('Error', 'Debe ingresar el n&uacute;mero. ');
            $("addressNumberId").focus();
            return false;
        }
        else if (!$("addressNumberId").value.match(new RegExp("^[0-9. ]*$", "i"))) {
            Ext.MessageBox.alert('Error', 'El n&uacute;mero ingresado no es v&aacute;lido. ');
            $("addressNumberId").focus();
            return false;
        }
        if (Util.valid.isBlank($("addressCityId").value)) {
            Ext.MessageBox.alert('Error', 'Debe ingresar la ciudad. ');
            $("addressCityId").focus();
            return false;
        }
        if (Util.valid.isBlank($("addressTownId").value)) {
            Ext.MessageBox.alert('Error', 'Debe ingresar la localidad. ');
            $("addressTownId").focus();
            return false;
        }
        if(!Util.valid.isBlank($("emailId").value) && !$("emailId").value.match(new RegExp("^.+@.+\\..+$", "i"))) {
            Ext.MessageBox.alert('Error', 'La direcci&oacute;n de email no es v&aacute;lida. ');
            $("emailId").focus();
            return false;
        }
        if(!Util.valid.isBlank($("email2Id").value) && !$("email2Id").value.match(new RegExp("^.+@.+\\..+$", "i"))) {
            Ext.MessageBox.alert('Error', 'La direcci&oacute;n de email alternativo no es v&aacute;lida. ');
            $("email2Id").focus();
            return false;
        }
        if(!Util.valid.isBlank($("degreeYearId").value) && !$("degreeYearId").value.match(new RegExp("^\\d+$", "i"))) {
            Ext.MessageBox.alert('Error', 'El a&ntilde;o de egreso debe ser num&eacute;rico. ');
            $("degreeYearId").focus();
            return false;
        }
        return true;
    }
</script>

<div class="errors">
    <html:errors />
</div>

<%-- El ID del form NO debe ser modificado. Se usa desde el menu --%>
<html:form action="/protected/showNewStudent" styleId="studentFormId">

    <h2>Alta de participante</h2>
    
    <div class="studentEdit">
        <table class="tableData" cellspacing="0">
            <tr>
                <td class="tableDataTitle">
                    Nombres*
                </td>
                <td class="tableDataValue">
                    <html:text property="name" styleId="nameId" value="" size="45" maxlength="45" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Apellidos*
                </td>
                <td class="tableDataValue">
                    <html:text property="surname" styleId="surnameId" value="" size="45" maxlength="45" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Tipo de documento
                </td>
                <td class="tableDataValue">
                    <html:select property="selectedIdType" styleClass="allSelects" styleId="selectedIdTypeId">
                        <html:optionsCollection property="idTypeOptions"/>
                    </html:select>
                </td>            
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Documento*
                </td>
                <td class="tableDataValue">
                    <html:text property="personalId" styleId="personalIdId" value="" size="25" maxlength="25" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Nacionalidad*
                </td>
                <td class="tableDataValue">
                    <html:text property="nationality" styleId="nationalityId" value="" size="25" maxlength="25" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Tel. Particular
                </td>
                <td class="tableDataValue">
                    <html:text property="phone" name="studentForm" styleId="phoneId" value="" size="25" maxlength="25" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Tel. Laboral
                </td>
                <td class="tableDataValue">
                    <html:text property="workPhone" name="studentForm" styleId="workPhoneId" value="" size="25" maxlength="25" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Tel. Celular
                </td>
                <td class="tableDataValue">
                    <html:text property="mobile" name="studentForm" styleId="mobileId" value="" size="25" maxlength="25" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Email
                </td>
                <td class="tableDataValue">
                    <html:text property="email" name="studentForm" styleId="emailId" value="" size="50" maxlength="75" />
                </td>
            </tr><td class="tableDataTitle"></td><td class="tableDataValue"></td><tr>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Email alternativo
                </td>
                <td class="tableDataValue">
                    <html:text property="email2" name="studentForm" styleId="email2Id" value="" size="50" maxlength="75" />
                </td>
            </tr><td class="tableDataTitle"></td><td class="tableDataValue"></td><tr>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Direcci&oacute;n
                </td>
                <td class="tableDataValue">
                 <table>
                	<tr>
	                	<td>
                    		Calle*
                    	</td>
                		<td>
                    		<html:text property="addressStreet" name="studentForm" styleId="addressStreetId" />
                    	</td>
                	</tr>
                	<tr>
	                	<td>
                    		N&uacute;mero*
                    	</td>
                		<td>
							<html:text property="addressNumber" name="studentForm" styleId="addressNumberId" />
                    	</td>
                	</tr>
                	<tr>
	                	<td>
                    		Piso
                    	</td>
                		<td>
							<html:text property="addressFloor" name="studentForm" styleId="addressFloorId" />
                    	</td>
                	</tr>
                	<tr>
	                	<td>
                    		Departamento
                    	</td>
                		<td>
							<html:text property="addressRoom" name="studentForm" styleId="addressRoomId" />
                    	</td>
                	</tr>
                	<tr>
		                	<td>
	                    		C&oacute;digo Postal
	                    	</td>
	                		<td>
								<html:text property="addressZipCode" name="studentForm" styleId="addressZipCodeId" size="8" maxlength="8" />
	                    	</td>
                    	</tr>
                	<tr>
	                	<td>
                    		Ciudad*
                    	</td>
                		<td>
							<html:text property="addressCity" name="studentForm" styleId="addressCityId" />
                    	</td>
                	</tr>
                	<tr>
	                	<td>
                    		Localidad*
                    	</td>
                		<td>
							<html:text property="addressTown" name="studentForm" styleId="addressTownId" />
                    	</td>
                	</tr>
                 </table>
                </td>
            </tr>
            </tr><td class="tableDataTitle"></td><td class="tableDataValue"></td><tr>
            <tr>
                <td class="tableDataTitle">
                    Empresa
                </td>
                <td class="tableDataValue">
                    <html:text property="company" styleId="companyId" value="" size="50" maxlength="50" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Cargo
                </td>
                <td class="tableDataValue">
                    <html:text property="position" styleId="positionId" value="" size="50" maxlength="50" />
                </td>
            </tr>
            </tr><td class="tableDataTitle"></td><td class="tableDataValue"></td><tr>
            <tr>
                <td class="tableDataTitle">
                    T&iacute;tulo
                </td>
                <td class="tableDataValue">
                    <html:text property="degreeName" styleId="degreeNameId" value="" size="50" maxlength="100" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Universidad
                </td>
                <td class="tableDataValue">
                    <html:text property="university" styleId="universityId" value="" size="50" maxlength="50" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    A&ntilde;o de egreso
                </td>
                <td class="tableDataValue">
                    <html:text property="degreeYear" styleId="degreeYearId" value="" size="4" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Alumno Completo
                </td>
                <td class="tableDataValue">
                    <html:checkbox property="complete" styleId="completeId"/>
                </td>
            </tr>
            <tr>
            	<td class="tableDataValue" colspan="2">
                	<html:checkbox property="createCustomer" styleId="createCustomerId">Nuevo cliente a partir de estos datos</html:checkbox>
                </td>
            </tr>
          </table>
    
    	<br/>
    	<div id="clear"></div>
    	<p class="mensajeCamposObligatorios">Los campos marcados con un asterisco (*) son obligatorios.</p>
    	<div id="clear"></div>
    	
        <%-- No se valida seguridad ya que SOLO entran aca los administradores --%>
        <div class="panelButton">
            <input type="button" value="Guardar" onclick="createStudent();" title="Guarda el participante...." class="button">
        </div>  
    
    </div>

</html:form>

<%-- Inyectados por Javascript --%>
<div id="createDivId" class="hideClass">
    <html:form action="/protected/createStudent" styleId="createStudentFormId">
        <html:hidden property="name" value="" styleId="createNameId" />
        <html:hidden property="surname" value="" styleId="createSurnameId" />
        <html:hidden property="selectedIdType" value="" styleId="createIdTypeId" />
        <html:hidden property="personalId" value="" styleId="createPersonalIdId" />
        <html:hidden property="nationality" value="" styleId="createNationalityId" />
        <html:hidden property="email" value="" styleId="createEmailId" />
        <html:hidden property="email2" value="" styleId="createEmail2Id" />
        <html:hidden property="phone" value="" styleId="createPhoneId" />
        <html:hidden property="workPhone" value="" styleId="createWorkPhoneId" />
        <html:hidden property="mobile" value="" styleId="createMobileId" />
        <html:hidden property="addressStreet" value="" styleId="createStreetId" />
        <html:hidden property="addressNumber" value="" styleId="createNumberId" />
        <html:hidden property="addressFloor" value="" styleId="createFloorId" />
        <html:hidden property="addressRoom" value="" styleId="createRoomId" />
        <html:hidden property="addressZipCode" value="" styleId="createZipCodeId" />
        <html:hidden property="addressCity" value="" styleId="createCityId" />
        <html:hidden property="addressTown" value="" styleId="createTownId" />
        <html:hidden property="company" value="" styleId="createCompanyId" />
        <html:hidden property="position" value="" styleId="createPositionId" />
        <html:hidden property="degreeName" value="" styleId="createDegreeNameId" />
        <html:hidden property="university" value="" styleId="createUniversityId" />
        <html:hidden property="degreeYear" value="" styleId="createDegreeYearId" />
        <html:hidden property="createCustomer" value="" styleId="createCreateCustomerId" />
        <html:hidden property="complete" value="" styleId="createCompleteId" />
    </html:form>
</div>
